package com.cntaiping.bass.child.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
* @author yangjiabin
* @version 创建时间：2018年4月27日 下午1:32:22
* 前后端跨域
*/
@Configuration
public class CorsConfig {
	 private CorsConfiguration buildConfig() {
	        CorsConfiguration corsConfiguration = new CorsConfiguration();
	        corsConfiguration.addAllowedOrigin("*"); // 1
	        corsConfiguration.addAllowedHeader("*"); // 2
	        corsConfiguration.addAllowedMethod("*"); // 3
	        return corsConfiguration;
	    }
	   @Bean
	    public CorsFilter corsFilter() {
	        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
	        source.registerCorsConfiguration("/**", buildConfig()); // 4
	        return new CorsFilter(source);
	    }
}
